home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / util / pack / xpk_Source.lha / xpk_Source / test / testMemPack.c < prev    next >
C/C++ Source or Header  |  1998-11-09  |  2KB  |  93 lines

  1. #define NAME        "testMemPack"
  2. #define DISTRIBUTION    "(Freeware) "
  3. #define REVISION    "4"
  4. #define SDI_ENDCODE_NOCTRLC
  5.  
  6. /* Programmheader
  7.  
  8.     Name:        testMemPack
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    tests Xpk Pack function
  12.     Compileropts:    -
  13.     Linkeropts:    -l xpkmaster amiga
  14.  
  15.  1.1   06.12.96 : fixed for new includes, added new WriteXpkFib
  16.  1.2   28.12.96 : changed TO/A to TO
  17.  1.3   15.04.97 : removed WriteXpkFib.c
  18.  1.4   28.11.97 : moved chunk-hook into include file
  19. */
  20.  
  21. #include <proto/exec.h>
  22. #include <proto/dos.h>
  23. #include <proto/xpkmaster.h>
  24. #include <exec/memory.h>
  25. #include "SDI_defines.h"
  26. #include "chunkhook.c"
  27.  
  28. struct Library        *XpkBase        = 0;
  29. ULONG            DosVersion        = 37;
  30. STRPTR            ibuf            = 0,
  31.             obuf            = 0;
  32. ULONG            ibuflen            = 0,
  33.             obuflen            = 0;
  34. BPTR            fh            = 0;
  35. struct RDArgs        *rda            = 0;
  36. struct FileInfoBlock    *fib            = 0;
  37.  
  38. #define PARAM "FROM/A,TO,METHOD"
  39.  
  40. void main(void)
  41. {
  42.   UBYTE errbuf[XPKERRMSGSIZE+1];
  43.   ULONG olen;
  44.   struct {
  45.     STRPTR from;
  46.     STRPTR to;
  47.     STRPTR method;
  48.   } args = {0,0,"USER"};
  49.  
  50.   if(!(rda = ReadArgs(PARAM, (LONG *) &args, 0)) ||
  51.   !(XpkBase = OpenLibrary(XPKNAME, 0)) ||
  52.   !(fh = Open(args.from, MODE_OLDFILE)) ||
  53.   !(fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, 0)) ||
  54.   !(ExamineFH(fh, fib)) ||
  55.   !(ibuf = (STRPTR) AllocMem(fib->fib_Size, MEMF_ANY)) ||
  56.   Read(fh, ibuf, fib->fib_Size) != fib->fib_Size)
  57.     End(RETURN_FAIL);
  58.  
  59.   ibuflen = fib->fib_Size;
  60.   Close(fh); fh = 0;
  61.  
  62.   if(XpkPackTags(XPK_InBuf, ibuf, XPK_InLen, ibuflen,
  63.     XPK_PackMethod, args.method, XPK_GetOutBuf,
  64.     &obuf, XPK_GetOutBufLen, &obuflen, XPK_GetOutLen, &olen,
  65.     XPK_GetError, errbuf, XPK_ChunkHook, &chunkhook, TAG_DONE))
  66.   {
  67.     STRPTR a = errbuf;
  68.     VPrintf("Can't XpkPack: %s\n", &a);
  69.     End(RETURN_FAIL);
  70.   }
  71.  
  72.   if(args.to)
  73.   {
  74.     if(!(fh = Open(args.to, MODE_NEWFILE)) ||
  75.     Write(fh, obuf, olen) != olen)
  76.       End(RETURN_FAIL);
  77.   }
  78.  
  79.   End(RETURN_OK);
  80. }
  81.  
  82.  
  83. void end(void)
  84. {
  85.   if(fh)    Close(fh);
  86.   if(XpkBase)    CloseLibrary(XpkBase);
  87.   if(fib)    FreeDosObject(DOS_FIB, fib);
  88.   if(rda)    FreeArgs(rda);
  89.   if(ibuf)    FreeMem(ibuf, ibuflen);
  90.   if(obuf)    FreeMem(obuf, obuflen);
  91. }
  92.  
  93.